<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑图书 - 图书管理系统</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #3f51b5;
            --secondary-color: #f50057;
            --bg-color: #f5f5f5;
            --card-color: #ffffff;
            --text-color: #333333;
            --text-light: #666666;
            --border-color: #e2e8f0;
            --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            --border-radius: 8px;
            --focus-shadow: 0 0 0 3px rgba(63, 81, 181, 0.25);
            --transition: all 0.3s ease;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        body {
            background-color: var(--bg-color);
            color: var(--text-color);
            line-height: 1.6;
        }

        .navbar {
            background-color: var(--primary-color);
            color: white;
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: var(--shadow);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .navbar-brand {
            font-size: 1.5rem;
            font-weight: bold;
            display: flex;
            align-items: center;
        }

        .navbar-brand i {
            margin-right: 0.5rem;
        }

        .navbar-links {
            display: flex;
            gap: 1.5rem;
        }

        .navbar a {
            color: white;
            text-decoration: none;
            padding: 0.5rem 0;
            position: relative;
            font-weight: 500;
            transition: color 0.3s;
        }

        .navbar a:hover {
            color: rgba(255, 255, 255, 0.8);
        }

        .navbar a::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            background-color: white;
            bottom: 0;
            left: 0;
            transition: width 0.3s;
        }

        .navbar a:hover::after {
            width: 100%;
        }

        .container {
            max-width: 800px;
            margin: 2rem auto;
            padding: 2rem;
            background: var(--card-color);
            border-radius: var(--border-radius);
            box-shadow: var(--shadow);
        }

        .page-title {
            color: var(--primary-color);
            margin-bottom: 1.5rem;
            padding-bottom: 1rem;
            border-bottom: 2px solid var(--primary-color);
            font-size: 1.8rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .form-container {
            margin-top: 1.5rem;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 500;
            color: var(--text-color);
        }

        .form-control {
            width: 100%;
            padding: 0.75rem 1rem;
            border: 1px solid var(--border-color);
            border-radius: var(--border-radius);
            font-size: 1rem;
            transition: var(--transition);
            background-color: white;
        }

        .form-control:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: var(--focus-shadow);
        }

        textarea.form-control {
            resize: vertical;
            min-height: 120px;
        }

        .btn {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.75rem 1.5rem;
            background-color: var(--primary-color);
            color: white;
            text-decoration: none;
            border-radius: var(--border-radius);
            font-size: 1rem;
            font-weight: 500;
            transition: var(--transition);
            border: none;
            cursor: pointer;
        }

        .btn:hover {
            background-color: #303f9f;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
        }

        .btn-danger {
            background-color: var(--secondary-color);
        }

        .btn-danger:hover {
            background-color: #c51162;
        }

        .action-buttons {
            display: flex;
            gap: 1rem;
            margin-top: 1rem;
        }

        .error-message {
            color: var(--secondary-color);
            background-color: rgba(245, 0, 87, 0.1);
            padding: 0.75rem 1rem;
            border-radius: var(--border-radius);
            margin-bottom: 1.5rem;
            display: none;
        }

        .error-message.show {
            display: block;
        }

        .required-field::after {
            content: " *";
            color: var(--secondary-color);
        }

        .form-hint {
            display: block;
            font-size: 0.85rem;
            color: var(--text-light);
            margin-top: 0.3rem;
        }

        footer {
            background-color: var(--primary-color);
            color: white;
            text-align: center;
            padding: 1.5rem 0;
            margin-top: 3rem;
        }

        @media (max-width: 768px) {
            .navbar {
                flex-direction: column;
                padding: 1rem;
            }

            .navbar-brand {
                margin-bottom: 1rem;
            }

            .container {
                margin: 1rem;
                padding: 1.5rem 1rem;
            }

            .form-group {
                margin-bottom: 1rem;
            }

            .btn {
                padding: 0.6rem 1.2rem;
            }

            .action-buttons {
                flex-direction: column;
                gap: 0.5rem;
            }

            .action-buttons .btn {
                width: 100%;
                justify-content: center;
            }
        }
    </style>
</head>
<body>
<nav class="navbar">
    <div class="navbar-brand">
        <i class="fas fa-book"></i>
        <span>图书管理系统</span>
    </div>
    <div class="navbar-links">
        <a href="/"><i class="fas fa-home"></i> 首页</a>
        <a href="/book/list"><i class="fas fa-list"></i> 我的图书</a>
        <a href="/logout"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
    </div>
</nav>

<div class="container">
    <h1 class="page-title"><i class="fas fa-edit"></i> 编辑图书</h1>

    <div class="form-container">
        <form id="bookForm" action="/book/edit" method="post">
            <div id="error-message" class="error-message"></div>

            <input type="hidden" name="id" th:value="${book.id}">

            <div class="form-group">
                <label for="title" class="required-field">书名</label>
                <input type="text" id="title" name="title" class="form-control" th:value="${book.title}" required>
            </div>

            <div class="form-group">
                <label for="author" class="required-field">作者</label>
                <input type="text" id="author" name="author" class="form-control" th:value="${book.author}" required>
            </div>

            <div class="form-group">
                <label for="publisher">出版社</label>
                <input type="text" id="publisher" name="publisher" class="form-control" th:value="${book.publisher}">
            </div>

            <div class="form-group">
                <label for="publicationDate">出版日期</label>
                <input type="date" id="publicationDate" name="publicationDate" class="form-control"
                       th:value="${book.publicationDate != null ? #dates.format(book.publicationDate, 'yyyy-MM-dd') : ''}">
            </div>

            <div class="form-group">
                <label for="isbn">ISBN</label>
                <input type="text" id="isbn" name="isbn" class="form-control" th:value="${book.isbn}">
                <span class="form-hint">例如：978-7-XXXXX-XXX-X</span>
            </div>

            <div class="form-group">
                <label for="category">分类</label>
                <input type="text" id="category" name="category" class="form-control" th:value="${book.category}">
                <span class="form-hint">例如：小说、科技、历史等</span>
            </div>

            <div class="form-group">
                <label for="description">描述</label>
                <textarea id="description" name="description" class="form-control" rows="4" th:text="${book.description}"></textarea>
            </div>

            <div class="form-group action-buttons">
                <button type="submit" class="btn"><i class="fas fa-save"></i> 保存修改</button>
                <a href="/book/list" class="btn btn-danger"><i class="fas fa-times"></i> 取消</a>
            </div>
        </form>
    </div>
</div>

<footer>
    <p>&copy; 2025 图书管理系统 - 让图书管理更简单</p>
</footer>

<script src="/js/script.js"></script>
<script>
    // 表单验证脚本
    document.getElementById('bookForm').addEventListener('submit', function(e) {
        const title = document.getElementById('title').value.trim();
        const author = document.getElementById('author').value.trim();
        const errorMessage = document.getElementById('error-message');

        if (title === '' || author === '') {
            e.preventDefault();
            errorMessage.textContent = '请填写必填字段！';
            errorMessage.classList.add('show');
            return false;
        }

        return true;
    });
</script>
</body>
</html>